package com.foreveross.taskservice.application.impl.task.service;

import java.util.List;

import org.openkoala.koala.commons.domain.jpa.KoalaEntityRepositoryJpa;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.foreveross.taskservice.application.task.service.IBuildTaskQueueLogApplication;
import com.foreveross.taskservice.core.domain.task.TaskQueueRecordEntity;
import com.foreveross.taskservice.core.domain.task.TaskTemplateEntity;
import com.foreveross.taskservice.infra.util.DateUtil;
@Service
@Transactional
public class BuildTaskQueueLogApplicationImpl extends KoalaEntityRepositoryJpa implements IBuildTaskQueueLogApplication{
	
	

	@Override
	public List<TaskQueueRecordEntity> buildTaskQueueRecords(
			TaskTemplateEntity t) throws Exception {
		return t.buildQueue();
	}

	/**
	 * 通过可变的日期参数构建抓取记录
	 * @param t
	 * @param start
	 * @param end
	 * @return
	 */
	private TaskQueueRecordEntity buildRecord(TaskTemplateEntity t,int start,Integer end){
		return 
				new TaskQueueRecordEntity(
						t.getFromCity(), t.getFromCityName(), t.getToCity(), t.getToCityName(),
						DateUtil.getDateAfter(start), 
						end==null||end<0?"":DateUtil.getDateAfter(start+end),
								t.getIsInternational()==null?0:t.getIsInternational().intValue(), end==null||end<0?0:1, 
								t.getGrabChannelId(), t.getGrabChannel(), t.getAreaCode(), t.getAreaName(), t.getAttachHbaseKey(), t.getPriority());
			
	}
}
